"""
获取TB商品信息，输入任意商品ID，返回该商品信息。（不使用Selenium）
商品信息包含以下两部分：
1、商品基本信息
商品标题、主图、月销量、原价、优惠价等
2、优惠券信息

"""

import requests
import time
from lxml import etree
import re
import json

# 宝贝收藏
# 获取淘宝价以及交易成功
# https://h5api.m.tmall.com/h5/mtop.macao.market.activity.applycoupon.querycouponsfordetail/1.0/?jsv=2.4.16&appKey=12574478&t=626366582836&sign=b3ea9910adc545f1ddf2a3cdd60f85db&api=mtop.macao.market.activity.applycoupon.querycouponsfordetail&v=1.0&timeout=30000&ttid=600000%40taobao_android_7.8.2.50823&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22detail_v%22%3A%223.1.2%22%2C%22from%22%3A%22detail%22%2C%22pageType%22%3A%22weex%22%2C%22itemId%22%3A%22522186974070%22%2C%22sellerId%22%3A%22129663914%22%2C%22sellerType%22%3A%22C%22%2C%22ttid%22%3A%22600000%40taobao_android_7.8.2.50823%22%7D

coupon = []
url = "https://h5api.m.tmall.com/h5/mtop.macao.market.activity.applycoupon.querycouponsfordetail/1.0/?jsv=2.4.16&appKey=12574478&t=1604755134185&sign=b3ea9910adc545f1ddf2a3cdd60f85db&api=mtop.macao.market.activity.applycoupon.querycouponsfordetail&v=1.0&timeout=30000&ttid=600000%40taobao_android_7.8.2.50823&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22detail_v%22%3A%223.1.2%22%2C%22from%22%3A%22detail%22%2C%22pageType%22%3A%22weex%22%2C%22itemId%22%3A%22522186974070%22%2C%22sellerId%22%3A%22129663914%22%2C%22sellerType%22%3A%22C%22%2C%22ttid%22%3A%22600000%40taobao_android_7.8.2.50823%22%7D"
header = {
    "referer": "https://pages.tmall.com/",
    "user-agent": "Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Mobile Safari/537.36",
    "cookie": "cna=XcenFwGFcFwCAatzeVWTYooV; hng=CN%7Czh-CN%7CCNY%7C156; xlly_s=1; _l_g_=Ug%3D%3D; login=true; lid=%E9%9C%B8%E6%B0%94%E7%9A%842216934861; t=fcd93188df06f25cb06bdb761be84c28; enc=JF9RKzTCLKahrxkB97eN3z0h6vp1S35jARGRvUY%2ByArDOP9TGjYKhN7wOFVJDFZzecFOVjtsXO%2B6cj0VwNsDHA%3D%3D; _tb_token_=3388d9bbb3670; cookie2=1726e85c58557391459b9cac18bf502b; _m_h5_tk=6d0c7ce22d23b22819c2483b1acc62c8_1604764458286; _m_h5_tk_enc=62a60bab2cbe253d80ef215db38310b0; dnk=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; uc1=cookie15=UtASsssmOIJ0bQ%3D%3D&cookie21=WqG3DMC9Edo1TBf%2BfpfnBg%3D%3D&cookie14=Uoe0abXOmNEtzw%3D%3D&existShop=false; uc3=vt3=F8dCufOHwAt9dTu8hI8%3D&nk2=sE6NkOtYY%2FVDWJ1wymnVTQ%3D%3D&id2=UU6hRiWBUBOyyQ%3D%3D&lg2=URm48syIIVrSKA%3D%3D; tracknick=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; uc4=id4=0%40U2xsBht3XQz4f%2B%2BXp8T%2FLxcDpiND&nk4=0%40srYN9PmlfOJ3FrdT5l9MvK8icEuYStQJAu3P; unb=2602534947; lgc=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; cookie1=B0BWmHHam1iCQGGINrJYO%2B3Fr3xZy1cY66%2BcpgkFOUw%3D; cookie17=UU6hRiWBUBOyyQ%3D%3D; _nk_=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; sgcookie=E100D5S0kd5oQXhyQVav%2FCmPLCrpavFu5xmfoRDD4tPmIXiTm1P%2FSpNaJ7lIYlYNSbTn%2BiMKg0fFTmSD18Z0QFfH9Q%3D%3D; sg=175; csg=6dc03e2d",
}
response = requests.get(url, headers=header)

data = response.text.strip(" mtopjsonp1(")
data = data.strip(");")
json_data = json.loads(data)
print(json_data)
# data_list = json_data["data"]["coupons"]
# for i in data_list:
#     new_i = i['couponList']
#     for j in new_i:
#         coupon.append(j["subtitles"][0])
#
# print("消费卷",coupon)
"""

https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?jsv=2.6.1&appKey=12574478&t=1604758907707&sign=3b8fee0d4a892eb83e6a6fd9078bd689&api=mtop.taobao.detail.getdetail&v=6.0&isSec=0&ecode=0&AntiFlood=true&AntiCreep=true&H5Request=true&ttid=2018%40taobao_h5_9.9.9&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22spm%22%3A%22a215s.7406091.recommend.26.35a46770tEF9sP%22%2C%22id%22%3A%22522186974070%22%2C%22scm%22%3A%221007.18975.103645.0%22%2C%22pvid%22%3A%22e396d0ec-7a6a-4747-8f58-ba5a1ba5c855%22%2C%22utparam%22%3A%22%7B%5C%22ranger_buckets_native%5C%22%3A%5C%22%5C%22%2C%5C%22x_object_type%5C%22%3A%5C%22item%5C%22%2C%5C%22mtx_ab%5C%22%3A9%2C%5C%22mtx_sab%5C%22%3A0%2C%5C%22scm%5C%22%3A%5C%221007.18975.103645.0%5C%22%2C%5C%22x_object_id%5C%22%3A%5C%22522186974070%5C%22%7D%22%2C%22itemNumId%22%3A%22522186974070%22%2C%22itemId%22%3A%22522186974070%22%2C%22exParams%22%3A%22%7B%5C%22spm%5C%22%3A%5C%22a215s.7406091.recommend.26.35a46770tEF9sP%5C%22%2C%5C%22id%5C%22%3A%5C%22522186974070%5C%22%2C%5C%22scm%5C%22%3A%5C%221007.18975.103645.0%5C%22%2C%5C%22pvid%5C%22%3A%5C%22e396d0ec-7a6a-4747-8f58-ba5a1ba5c855%5C%22%2C%5C%22utparam%5C%22%3A%5C%22%7B%5C%5C%5C%22ranger_buckets_native%5C%5C%5C%22%3A%5C%5C%5C%22%5C%5C%5C%22%2C%5C%5C%5C%22x_object_type%5C%5C%5C%22%3A%5C%5C%5C%22item%5C%5C%5C%22%2C%5C%5C%5C%22mtx_ab%5C%5C%5C%22%3A9%2C%5C%5C%5C%22mtx_sab%5C%5C%5C%22%3A0%2C%5C%5C%5C%22scm%5C%5C%5C%22%3A%5C%5C%5C%221007.18975.103645.0%5C%5C%5C%22%2C%5C%5C%5C%22x_object_id%5C%5C%5C%22%3A%5C%5C%5C%22522186974070%5C%5C%5C%22%7D%5C%22%7D%22%2C%22detail_v%22%3A%228.0.0%22%2C%22utdid%22%3A%221%22%7D

https://h5api.m.tmall.com/h5/mtop.user.getusersimple/1.0/?jsv=2.4.11&appKey=12574478&t=1604760884857&sign=bdfda0554291a90cb6fa30e37ae4e757&api=mtop.user.getUserSimple&v=1.0&H5Request=true&jsonpIncPrefix=smb_xc&timeout=2000&type=jsonp&dataType=jsonp&callback=mtopjsonpsmb_xc1&data=%7B%7D

"""
#
# parent = {
#     "itemId": "626366582836",
#     "sellerId": "2034387967",
#     "modules": "dynStock,qrcode,viewer,price,duty,xmpPromotion,delivery,activity,fqg,zjys,couponActivity,soldQuantity,page,originalPrice,tradeContract"
# }
#
# header = {
#     "referer": "https://item.taobao.com/item.htm?spm=a230r.1.14.70.48111dd8i7mud1&id=626366582836&ns=1&abbucket=7",
#     "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36",
#     "cookie": "cna=XcenFwGFcFwCAatzeVWTYooV; t=8d979e5242099448c9873f4c7a076f0a; cookie2=14a3aa57c44763eb38e380ee07f9d0e0; v=0; hng=CN%7Czh-CN%7CCNY%7C156; thw=cn; _samesite_flag_=true; miid=2045236895702146442; xlly_s=1; tk_trace=oTRxOWSBNwn9dPyorMJE%2FoPdY8zfvmw%2Fq5v3h2WGHuet%2BOuHFb9QOtYFO6aQggSX5MefxDqhcPcy6aTa8du%2FI5diFhlWQRT%2FH9OX%2B6I05pUjHpPe%2BHbIoZ04Av9esxOwM8sifJlJz9ghAN1BRX06meAStxrM58qC3ouO2EeDB6KQdWReoW5Jm8KUZTwUhbQNkmnjkT63BzDnAOG39gbn%2FbgubYj6Pq6MS%2By3%2BoebaAkOIpsYo7jtXTRBCHfLWtKe3Da908Pag%2B0eoihA%2F2PsZCjJy%2FF53dA%3D; lLtC1_=1; sgcookie=E100%2Bl5EKkpeb4sNUrs9JoQ2b0fqnrbsQsJjEILc8huaQ%2Bo%2BiPRVBetQh1i1agXuoGmuo60rkRyqtqO2Yz8kElqYsQ%3D%3D; unb=2602534947; uc3=lg2=V32FPkk%2Fw0dUvg%3D%3D&nk2=sE6NkOtYY%2FVDWJ1wymnVTQ%3D%3D&vt3=F8dCufOHxglIvZylRu8%3D&id2=UU6hRiWBUBOyyQ%3D%3D; csg=df96cbe2; lgc=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; cookie17=UU6hRiWBUBOyyQ%3D%3D; dnk=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; skt=556d22da270268c9; existShop=MTYwNDczMDU0Mw%3D%3D; uc4=id4=0%40U2xsBht3XQz4f%2B%2BXp8T%2FLxECyq%2Bp&nk4=0%40srYN9PmlfOJ3FrdT5l9MvK8icEuYStK1Za8n; tracknick=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; _cc_=VFC%2FuZ9ajQ%3D%3D; _l_g_=Ug%3D%3D; sg=175; _nk_=%5Cu6E38%5Cu76CA%5Cu7AE01246268651; cookie1=B0BWmHHam1iCQGGINrJYO%2B3Fr3xZy1cY66%2BcpgkFOUw%3D; mt=ci=71_1; ubn=p; enc=wBeHsWdIRL2WNCGCHI6x3kvJ4dHSIW%2F8Kf7NXOnKABCx2h9wHdoiWnYlr8td6B2TjJtNfN0hN02KRj7%2FNdJMkg%3D%3D; ucn=center; uc1=pas=0&cookie14=Uoe0abXI2UaY9Q%3D%3D&cookie21=Vq8l%2BKCLiv0MzbofZcj7fA%3D%3D&cookie15=U%2BGCWk%2F75gdr5Q%3D%3D&cookie16=W5iHLLyFPlMGbLDwA%2BdvAGZqLg%3D%3D&existShop=false; _m_h5_tk=b2cbafa3395bf8de4cc588c8ee69790f_1604747607623; _m_h5_tk_enc=f91777b04b218c1cc6ec0375dceeb319; _tb_token_=eb7a631b7d66e; isg=BK6u80TLfT_Q3YnbNk_tPIZQ_wRwr3KpOJDfuNh3rLFhu08VQD_QuMX6cydXZGrB; l=eBTdACDRO6kBUi7KBO5Zourza77teIRb81PzaNbMiInca15fsFSAwNQV4I7D-dtjgtfAcetyGmkaaRKQv3adVxDDBeDzH13fPxJ6-; tfstk=c_gCBNcKi9XIL1xP8XOaTh1LwmaVZDp_sHwKODHW0WMGuxlCieb4h55nqObTD51..",
# }
#
#
# url = "https://item.taobao.com/item.htm?spm=a230r.1.14.206.7c8d33a3aOfW3b&id=626366582836"
# response = requests.get(url,headers=header).content
# html_str = etree.HTML(response)
# title = html_str.xpath('//*[@id="J_Title"]/h3/text()')
# print(title)
#
#
# url = "https://detailskip.taobao.com/service/getData/1/p1/item/detail/sib.htm"
#
# # img = "https://gd4.alicdn.com/imgextra/i1/{}/O1CN01SrUGcY28iw4cTULQ8_!!{}.jpg_400x400.jpg".format(str(parent.get("sellerId")),str(parent.get("sellerId")))
# response = requests.get(url, headers=header, params=parent).text
# data = json.loads(response)
#
# '''现获取交易成功数'''
# success_sum = data.get("data")["soldQuantity"]["confirmGoodsCount"]
# price = data.get("data")["price"]
# Current_price = data.get("data")["promotion"]["promoData"]["def"][0]["price"]
#
# print(response)
# print("月销售",success_sum)
# print("原价",price)
# print("现价",Current_price)
# # price("主图片",img)
"""





https://h5.m.taobao.com/awp/core/detail.htm?spm=a215s.7406091.recommend.17.35a46770tIUm7l&id=626366582836&scm=1007.18975.103645.0&pvid=a258de82-e16f-4874-9418-f89ed55c8d94&utparam=%7B%22ranger_buckets_native%22%3A%22%22%2C%22x_object_type%22%3A%22item%22%2C%22mtx_ab%22%3A8%2C%22mtx_sab%22%3A0%2C%22scm%22%3A%221007.18975.103645.0%22%2C%22x_object_id%22%3A%22626366582836%22%7D
https://h5.m.taobao.com/awp/core/detail.htm?spm=a215s.7406091.recommend.98.35a46770bSNheB&id=621856224081&scm=1007.18975.103645.0&pvid=15b6d728-4d69-419c-a094-2e29f301bf79&utparam=%7B%22ranger_buckets_native%22%3A%22%22%2C%22x_object_type%22%3A%22item%22%2C%22mtx_ab%22%3A8%2C%22mtx_sab%22%3A0%2C%22scm%22%3A%221007.18975.103645.0%22%2C%22x_object_id%22%3A%22621856224081%22%7D


https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?jsv=2.6.1&appKey=12574478&t=1604763207493&sign=f39b1e0244353a01f165b05f1b85df5a&api=mtop.taobao.detail.getdetail&v=6.0&isSec=0&ecode=0&AntiFlood=true&AntiCreep=true&H5Request=true&ttid=2018%40taobao_h5_9.9.9&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22spm%22%3A%22a215s.7406091.recommend.17.35a46770tIUm7l%22%2C%22id%22%3A%22626366582836%22%2C%22scm%22%3A%221007.18975.103645.0%22%2C%22pvid%22%3A%22a258de82-e16f-4874-9418-f89ed55c8d94%22%2C%22utparam%22%3A%22%7B%5C%22ranger_buckets_native%5C%22%3A%5C%22%5C%22%2C%5C%22x_object_type%5C%22%3A%5C%22item%5C%22%2C%5C%22mtx_ab%5C%22%3A8%2C%5C%22mtx_sab%5C%22%3A0%2C%5C%22scm%5C%22%3A%5C%221007.18975.103645.0%5C%22%2C%5C%22x_object_id%5C%22%3A%5C%22626366582836%5C%22%7D%22%2C%22itemNumId%22%3A%22626366582836%22%2C%22itemId%22%3A%22626366582836%22%2C%22exParams%22%3A%22%7B%5C%22spm%5C%22%3A%5C%22a215s.7406091.recommend.17.35a46770tIUm7l%5C%22%2C%5C%22id%5C%22%3A%5C%22626366582836%5C%22%2C%5C%22scm%5C%22%3A%5C%221007.18975.103645.0%5C%22%2C%5C%22pvid%5C%22%3A%5C%22a258de82-e16f-4874-9418-f89ed55c8d94%5C%22%2C%5C%22utparam%5C%22%3A%5C%22%7B%5C%5C%5C%22ranger_buckets_native%5C%5C%5C%22%3A%5C%5C%5C%22%5C%5C%5C%22%2C%5C%5C%5C%22x_object_type%5C%5C%5C%22%3A%5C%5C%5C%22item%5C%5C%5C%22%2C%5C%5C%5C%22mtx_ab%5C%5C%5C%22%3A8%2C%5C%5C%5C%22mtx_sab%5C%5C%5C%22%3A0%2C%5C%5C%5C%22scm%5C%5C%5C%22%3A%5C%5C%5C%221007.18975.103645.0%5C%5C%5C%22%2C%5C%5C%5C%22x_object_id%5C%5C%5C%22%3A%5C%5C%5C%22626366582836%5C%5C%5C%22%7D%5C%22%7D%22%2C%22detail_v%22%3A%228.0.0%22%2C%22utdid%22%3A%221%22%7D
https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?jsv=2.6.1&appKey=12574478&t=1604763299122&sign=c803e175f1d13975e7cef16a6635a45c&api=mtop.taobao.detail.getdetail&v=6.0&isSec=0&ecode=0&AntiFlood=true&AntiCreep=true&H5Request=true&ttid=2018%40taobao_h5_9.9.9&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22spm%22%3A%22a215s.7406091.recommend.98.35a46770bSNheB%22%2C%22id%22%3A%22621856224081%22%2C%22scm%22%3A%221007.18975.103645.0%22%2C%22pvid%22%3A%2215b6d728-4d69-419c-a094-2e29f301bf79%22%2C%22utparam%22%3A%22%7B%5C%22ranger_buckets_native%5C%22%3A%5C%22%5C%22%2C%5C%22x_object_type%5C%22%3A%5C%22item%5C%22%2C%5C%22mtx_ab%5C%22%3A8%2C%5C%22mtx_sab%5C%22%3A0%2C%5C%22scm%5C%22%3A%5C%221007.18975.103645.0%5C%22%2C%5C%22x_object_id%5C%22%3A%5C%22621856224081%5C%22%7D%22%2C%22itemNumId%22%3A%22621856224081%22%2C%22itemId%22%3A%22621856224081%22%2C%22exParams%22%3A%22%7B%5C%22spm%5C%22%3A%5C%22a215s.7406091.recommend.98.35a46770bSNheB%5C%22%2C%5C%22id%5C%22%3A%5C%22621856224081%5C%22%2C%5C%22scm%5C%22%3A%5C%221007.18975.103645.0%5C%22%2C%5C%22pvid%5C%22%3A%5C%2215b6d728-4d69-419c-a094-2e29f301bf79%5C%22%2C%5C%22utparam%5C%22%3A%5C%22%7B%5C%5C%5C%22ranger_buckets_native%5C%5C%5C%22%3A%5C%5C%5C%22%5C%5C%5C%22%2C%5C%5C%5C%22x_object_type%5C%5C%5C%22%3A%5C%5C%5C%22item%5C%5C%5C%22%2C%5C%5C%5C%22mtx_ab%5C%5C%5C%22%3A8%2C%5C%5C%5C%22mtx_sab%5C%5C%5C%22%3A0%2C%5C%5C%5C%22scm%5C%5C%5C%22%3A%5C%5C%5C%221007.18975.103645.0%5C%5C%5C%22%2C%5C%5C%5C%22x_object_id%5C%5C%5C%22%3A%5C%5C%5C%22621856224081%5C%5C%5C%22%7D%5C%22%7D%22%2C%22detail_v%22%3A%228.0.0%22%2C%22utdid%22%3A%221%22%7D
"""












